#include "pwm_test.h"

// 频率
static unsigned short g_musicFreq[] = {
    262,  277,  294,  311,  330,  349,  370,  392,  415,  440,  466,  496,
    523,  554,  587,  622,  659,  698,  740,  784,  831,  880,  932,  988,
    1046, 1109, 1175, 1245, 1318, 1397, 1480, 1568, 1661, 1760, 1865, 1976
};
static unsigned short g_musicTime[] = {
    1908, 1805, 1701, 1608, 1515, 1433, 1351, 1276, 1205, 1136, 1073, 1008,
    956,  903,  852,  804,  759,  716,  676,  638,  602,  568,  536,  506,
    478,  451,  426,  402,  379,  358,  338,  319,  301,  284,  268,  253
};
// 曲调
static unsigned char g_bpwsx[][2] = {
    {M6, 1}, {M6, 1}, {M6, 1}, {M6, 1}, {M6, 1}, {M7, 1}, {H1, 2}, {H1, 4}, {P, 1}, {M7, 2},{M6, 1},
    {M6, 1}, {M5, 2}, {M5, 1}, {M5, 1}, {M5, 1}, {M3, 1}, {M5, 1}, {M5, 4}, {P, 2}, {P, 1}, {M3, 1},
    {M6, 1}, {M6, 1}, {M6, 1}, {M6, 1}, {M6, 1}, {M6, 1}, {M5, 1}, {M5, 1}, {M6, 2}, {M6, 2}, {P, 2}, {M6, 1}, {M1, 1},
    {M2, 1}, {M2, 1}, {M2, 1}, {M2, 1}, {M2, 1}, {M1, 1}, {M1, 1}, {M3, 1}, {M3, 1}, {M2, 2}, {M2, 1}, {P, 1}, {M1, 1}, {M1, 1}, {M2, 1},
    {M3, 2}, {M5, 2}, {M5, 1}, {M5, 1}, {M3, 2}, {M5, 4}, {P, 1}, {M1, 1}, {M1, 1}, {M2, 1},
    {M3, 1}, {M6, 1}, {M6, 1}, {M6, 1}, {M6, 1}, {M6, 2}, {M6, 1}, {M6, 4}, {P, 1}, {M6, 1}, {M6, 1}, {M7, 1},
    {H1, 2}, {M6, 2}, {M6, 1}, {M5, 1}, {M5, 1}, {H1, 1}, {M6, 4}, {M6, 2},
    {M5, 2}, {M6, 2}, {M6, 4}, {M6, 4}, {P, 2}, {P, 1}, {M3, 1},
    {M6, 1}, {M6, 1}, {M6, 1}, {M6, 1}, {M6, 1}, {M6, 1}, {M6, 1}, {M6, 1}, {M6, 1}, {H1, 2}, {H1, 1}, {P, 1}, {M7, 1}, {M7, 1}, {M6, 1},
    {M5, 1}, {M5, 1}, {M5, 1}, {M5, 1}, {M5, 1}, {M6, 1}, {M3, 2}, {M5, 4}, {P, 2}, {P, 1}, {M3, 1},
    {M6, 1}, {M6, 1}, {M6, 1}, {M6, 1}, {M6, 1}, {M6, 1}, {M6, 1}, {M5, 1}, {P, 2}, {M5, 1}, {M6, 1}, {P, 1}, {M6, 1}, {M6, 1},{M1, 1},
    {M2, 1}, {M2, 1}, {M2, 1}, {M2, 1}, {M2, 2}, {M1, 1}, {M2, 1}, {M3, 1}, {M2, 1}, {M2, 2}, {P, 1}, {M1, 1}, {M1, 1}, {M2, 1},
    {M3, 1}, {M5, 1}, {M5, 1}, {M5, 1}, {M5, 2}, {M5, 1}, {M5, 1}, {M3, 2}, {M5, 2}, {P, 1}, {M1, 1}, {M1, 1}, {M2, 1},
    {M3, 1}, {M6, 1}, {M6, 1}, {M6, 1}, {M6, 1}, {M6, 2}, {M6, 1}, {H1, 2}, {M6, 2}, {P, 1}, {M6, 1}, {M6, 1}, {M7, 1},
    {H1, 2}, {M6, 2}, {M6, 1}, {M5, 2}, {M5, 1}, {H1, 2}, {H2, 2}, {H2, 1}, {M7, 2}, {M5, 1},
    {M7, 1}, {M6, 2}, {M6, 1}, {M6, 4}, {M6, 4}, {H1, 2}, {H2, 2},
    {H3, 4}, {H3, 1}, {H2, 2}, {H1, 1}, {H2, 4}, {H2, 4},
    {H2, 1}, {H2, 1}, {H2, 1}, {H2, 1}, {H2, 1}, {H1, 1}, {H1, 2}, {H2, 2}, {H3, 1}, {M6, 1}, {M6, 2}, {M6, 1}, {M7, 1},
    {H1, 4}, {P, 1}, {M7, 2}, {H1, 1}, {H2, 4}, {P, 2}, {H1, 1}, {H2, 1},
    {H3, 2}, {H3, 2}, {H2, 1}, {H1, 1}, {H2, 1}, {H3, 1}, {H3, 4}, {H2, 2}, {H3, 2},
    {H6, 4}, {H6, 1}, {H5, 2}, {H2, 1}, {H2, 4}, {H2, 4},
    {H2, 1}, {H2, 1}, {H2, 1}, {H2, 1}, {H2, 1}, {H1, 1}, {H1, 2}, {H2, 2}, {H1, 1}, {M6, 1}, {M6, 1}, {M6, 1}, {M7, 1}, {H1, 1},
    {H1, 4}, {P, 1}, {M7, 2}, {H1, 1}, {H2, 4}, {H2, 2}, {M7, 2}, {M5, 2},
    {M7, 2}, {M6, 4}, {M6, 2}, {M6, 4}, {M6, 4}
};

void pwm_entry()
{
    printf("----- pwm test -----\n");
	// 初始化PWM端口
    IoTPwmInit(8);
	// 启动PWM, 占空比50%, 频率1HZ
	IoTPwmStart(8, 50, 1);
	// 延时
	LL_mDelay(1000*10);
	// 停止PWM
 	IoTPwmStop(8);
}

void pwm_task()
{
    UINT32 uwRet = -1;
    UINT32 taskID = 0;
    TSK_INIT_PARAM_S stTask = {0};
    stTask.pfnTaskEntry = (TSK_ENTRY_FUNC)pwm_entry;
    stTask.uwStackSize = 0x1000;
    stTask.pcName = "pwm task";
    stTask.usTaskPrio = 10;
    uwRet = LOS_TaskCreate(&taskID, &stTask);
    if (uwRet != LOS_OK) {
        printf("Task fs create failed\n");
    }
}